<?php
require_once('common.inc.php');
require_once(_INC_PATH.'database.php');
require_once(_INC_PATH.'captcha.inc');
require_once(_INC_PATH.'page.inc.php');
//get get value
if(is_array($_POST))
{
	foreach($_POST as $k=>$val){
		$arr_data[$k]=trim($val);
	}
}
//get post value
if(is_array($_GET))
{
	foreach($_GET as $k=>$val){
		$arr_data[$k]=trim($val);
	}
}

$db = new database();
$sql="SELECT count(*)as total
	  FROM tbl_estimate e 
	  LEFT JOIN tbl_corporation c ON e.cor_id=c.id
	  LEFT JOIN tbl_user u ON e.user_id=u.user_id
	  WHERE e.del_flg='0' order by e.update_time desc";
$total = $db->loadResult($sql);
$curPage = @intval($arr_data['p']);
if($curPage < 1) $curPage = 1;
$showNum = _FORVIEWNUM;
$pageLink = "/estimate.php";
$page = new PageClass($total,$curPage,$showNum,$pageLink);
$limitStart = $page->limitStart;
$smarty->assign("pageList",$page->pageList);

$sql="SELECT c.id,e.content,e.salary,e.environment,e.opportunity,e.pressure,
	  c.name,c.address,e.user_id,e.user_name,u.grade,u.point,e.id as eid 
	  FROM tbl_estimate e 
	  LEFT JOIN tbl_corporation c ON e.cor_id=c.id
	  LEFT JOIN tbl_user u ON e.user_id=u.user_id
	  WHERE e.del_flg='0' order by e.update_time desc limit $limitStart,$showNum";
$db->setQuery($sql);
$data = $db->loadList();
foreach($data as $key=>$value)
{
	if($value['user_name'] == _VISITOR){
		$data[$key]['faceImg'] = '/images/87face.gif';
	}elseif(findImg($value['user_id'],"face")){
		$data[$key]['faceImg'] = findImg($value['user_id'],"face");
	}else{
		$data[$key]['faceImg'] = '/images/noface.gif';
	}
	$data[$key]['content'] = content_replace($value['content'],$value['eid'],'est');
}
$smarty->assign('result',$data);
$smarty->assign('search_name',isset($arr_data['search_name'])?$arr_data['search_name']:"");
Display('estimate_list.tpl');
?>